const Koa=require('koa2');
const app=new Koa();
const sleep=ms=>new Promise((resolve,reject)=>{
    setTimeout(()=>{
        resolve();
    },ms);
});
const responseTime=()=>async (ctx,next)=>{
    let start=new Date();
    console.log('responseTime:',start);
    await next();
    let es=Date.now()-start;
    console.log('responseTime:',es);
};

app.use(responseTime());

const logger=()=>async (ctx,next)=>{
    console.log(['<--',ctx.method,ctx.url].join(' '));
    await next();
    console.log(['<--',ctx.method,ctx.url,ctx.response.status].join(' '));
};

app.use(logger());

app.use(async ctx=>{
    await sleep(500);
    console.log('Done');
    ctx.body=new Date().toLocaleString();
});


app.listen(3002,()=>{
    console.log('\n\nPort 3002',new Date().toLocaleTimeString());
});
